package com.sunny.ynhz.ui.index;

import android.content.Intent;
import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.amap.api.services.weather.LocalWeatherForecastResult;
import com.amap.api.services.weather.LocalWeatherLiveResult;
import com.amap.api.services.weather.WeatherSearch;
import com.amap.api.services.weather.WeatherSearchQuery;
import com.bumptech.glide.Glide;
import com.jauker.widget.BadgeView;
import com.sunny.ynhz.BuildingActivity;
import com.sunny.ynhz.R;
import com.sunny.ynhz.adapter.DailyBtnsAdapter;
import com.sunny.ynhz.adapter.TestActivity;
import com.sunny.ynhz.adapter.TestAdapter;
import com.sunny.ynhz.adapter.base.FragmentViewPagerAdapter;
import com.sunny.ynhz.api.HttpManager;
import com.sunny.ynhz.api.subscriber.ApiSubscriber;
import com.sunny.ynhz.bean.BannerBean;
import com.sunny.ynhz.bean.DailyBtnsBean;
import com.sunny.ynhz.bean.IndexProblemListBean;
import com.sunny.ynhz.bean.IndexProblemNumBean;
import com.sunny.ynhz.bean.NewsUnreadNumsBean;
import com.sunny.ynhz.bean.WaterInformBean;
import com.sunny.ynhz.event.ClickEvent;
import com.sunny.ynhz.servicebestpractice.Test;
import com.sunny.ynhz.ui.LakeMsgActivity;
import com.sunny.ynhz.ui.NewsStaticActivity;
import com.sunny.ynhz.ui.ProblemAllActivity;
import com.sunny.ynhz.ui.ProblemBillActivity;
import com.sunny.ynhz.ui.RedRiverMsgActivity;
import com.sunny.ynhz.ui.RiverMsgActivity;
import com.sunny.ynhz.ui.TestScorllActivity;
import com.sunny.ynhz.ui.WaitForToCheckActivity;
import com.sunny.ynhz.ui.ZjRiverMsgActivity;
import com.sunny.ynhz.ui.base.BaseFragment;
import com.sunny.ynhz.ui.daily.BannerDetailsActivity;
import com.sunny.ynhz.ui.daily.indexproblem.ProblemInfoActivity;
import com.sunny.ynhz.ui.daily.indexproblem.ProblemWaitForAcceptActivity;
import com.sunny.ynhz.ui.daily.indexproblem.RiverChiefsNameListActivity;
import com.sunny.ynhz.ui.daily.news.MyReportFragment;
import com.sunny.ynhz.ui.daily.news.RecentNewsFragment;
import com.sunny.ynhz.ui.daily.news.RepeatedComplaintsFragment;
import com.sunny.ynhz.ui.daily.specialcolumn.ExperienceExchangeActivity;
import com.sunny.ynhz.ui.daily.specialcolumn.RankNaviActivity;
import com.sunny.ynhz.ui.ynts.WxyyActivity;
import com.sunny.ynhz.ui.ynts.partorlstaticfragment.RiverStaticActivity;
import com.sunny.ynhz.ui.ynts.problemover.ProblemStaticActivity;
import com.sunny.ynhz.utils.GridSpacingItemDecoration;
import com.sunny.ynhz.utils.SPUtil;
import com.sunny.ynhz.utils.ShowUtils;
import com.sunny.ynhz.widget.CustomViewPager;
import com.sunny.ynhz.widget.MyListView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import cn.bingoogolapple.bgabanner.BGABanner;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/7/12/012.
 */

public class DailyFragment extends BaseFragment {
    @BindView(R.id.person_name)
    TextView personName;
    @BindView(R.id.addr)
    TextView addr;
    @BindView(R.id.weather)
    TextView weather;
    @BindView(R.id.index_btns_recyclerview)
    RecyclerView indexBtnsRecyclerview;
    @BindView(R.id.iv_water_inform)
    MyListView myListView;
    @BindView(R.id.id_stickynavlayout_indicator)
    TabLayout tb_title;
    @BindView(R.id.id_stickynavlayout_viewpager)
    CustomViewPager customViewPager;
    @BindView(R.id.special_column_btns_recyclerview)
    RecyclerView specialColumnBtnsRecyclrView;
    @BindView(R.id.patrol_news_recyclerview)
    RecyclerView patrolNewsRecyclerView;
    @BindView(R.id.tv_no_1)
    View tv_no_dsl;
    @BindView(R.id.tv_no_2)
    View tv_no_clz;
    @BindView(R.id.tv_no_4)
    View tv_no_ybj;
    @BindView(R.id.tv_no_5)
    View tv_no_wdjt;
    @BindView(R.id.tv_no_6)
    View tv_no_dfh;
    @BindView(R.id.tv_no_7)
    View tv_no_gzz;

    @BindView(R.id.banner)
    BGABanner banner;
    private List<WaterInformBean> waterInforms;
    ArrayList<Fragment> fragment;
    private BadgeView badgeView;
    private BadgeView badgeView2;
    private BadgeView badgeView3;
    private BadgeView badgeView4;
    private BadgeView badgeView6;
    private BadgeView badgeView7;

    //新闻动态的气泡
    private BadgeView badgeViewForNews;
    //经验交流的气泡
    private BadgeView badgeViewForExprence;
    //他山之石的气泡
    private BadgeView badgeViewForOtherStone;
    //河长须知的气泡
    private BadgeView badgeViewForRiverchiefKnow;
    //政策法规的气泡
    private BadgeView badgeViewForPolicies;
    //红黑榜的气泡
    private BadgeView badgeViewForRedBlackList;
    //通知公告的气泡
    private BadgeView badgeViewForNotice;

    private WeatherSearchQuery mquery;
    private WeatherSearch mweathersearch;
    private LinkedList<IndexProblemListBean.DataBean> patrolNewsList;
    private TestAdapter patrolNewsAdapter;
    //存放图片的id
    private int[] imageIds = new int[]{
            R.mipmap.tbbg, R.mipmap.tbbg, R.mipmap.tbbg, R.mipmap.tbbg,

    };
    private ArrayList<Object> imageArr;
    private DailyBtnsAdapter dailyBtnsAdapter;
    private Subscription subscribe;


    public static DailyFragment getInstanceDailyFragment() {
        return new DailyFragment();
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_daily;
    }

    @Override
    protected void setUpView() {
        super.setUpView();
        ShowUtils.closePopwindow();
        if (!SPUtil.get("name", "null").equals("null")) {
            personName.setText(SPUtil.get("name", "null").toString());
        }
        kjfsBtnsInit();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                getProblemNum(SPUtil.get("userId", "null").toString());
                getNewsUnreadNum(SPUtil.get("userId", "null").toString());
            }
        }, 200);
    }

    /**
     * 获取轮播banner
     */
    private void getBanner() {
        HttpManager.getInstance()
                .getBannerPic()
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ApiSubscriber(activity, new ApiSubscriber.HttpOnResultListener<BannerBean>() {
                    @Override
                    public void onNext(final BannerBean jsonObject) {
                        imageArr = new ArrayList<>();
                        for (int i = 0; i < jsonObject.getData().size(); i++) {
                            imageArr.add(jsonObject.getData().get(i).getPicurl());
                        }
                        banner.setAdapter(new BGABanner.Adapter<ImageView, String>() {
                            @Override
                            public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
                                Glide.with(activity)
                                        .load(model)
                                        .centerCrop()
                                        .dontAnimate()
                                        .into(itemView);
                            }
                        });

                        banner.setData(imageArr, Arrays.asList(""));//轮播图

                        banner.setDelegate(new BGABanner.Delegate<ImageView, String>() {
                            @Override
                            public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {
                                Intent intent = new Intent(activity, BannerDetailsActivity.class);
                                intent.putExtra("url", jsonObject.getData().get(position).getNewsurl());
                                startActivity(intent);
                            }
                        });
                    }

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onstart() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }

    /**
     * 获得首页动态的列表
     *
     * @param userId
     */
    private void getProblemList(String userId) {
        HttpManager.getInstance()
                .getPatrolNews(userId)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ApiSubscriber(activity, new ApiSubscriber.HttpOnResultListener<IndexProblemListBean>() {
                    @Override
                    public void onNext(IndexProblemListBean jsonObject) {
                        patrolNewsList.clear();
                        patrolNewsList.addAll(jsonObject.getData());
                        patrolNewsAdapter.notifyDataSetChanged();
                        if (jsonObject.getData().size() != 0) {

                        }
                    }

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onstart() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }

    /**
     * 获得首页四个问题分类的数量（红色圆点）
     *
     * @param userId
     */
    public void getProblemNum(String userId) {
        HttpManager.getInstance()
                .getProblemNums(userId)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ApiSubscriber(activity, new ApiSubscriber.HttpOnResultListener<IndexProblemNumBean>() {
                    @Override
                    public void onNext(IndexProblemNumBean jsonObject) {
                        if (jsonObject.getData() != null) {
                            IndexProblemNumBean bean = jsonObject;
                            String string = bean.getData().toString();
                            if (badgeView == null) {
                                badgeView = new BadgeView(activity);
                                badgeView.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeView.setTextSize(8);
                                badgeView.setTargetView(tv_no_dsl);
                            }
                            badgeView.setBadgeCount(jsonObject.getData().getPending());


                            if (badgeView2 == null) {
                                badgeView2 = new BadgeView(activity);
                                badgeView2.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeView2.setTextSize(8);
                                badgeView2.setTargetView(tv_no_clz);
                            }
                            badgeView2.setBadgeCount(jsonObject.getData().getInProcess());

                            if (badgeView3 == null) {
                                badgeView3 = new BadgeView(activity);
                                badgeView3.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeView3.setTextSize(8);
                                badgeView3.setTargetView(tv_no_ybj);
                            }
                            badgeView3.setBadgeCount(jsonObject.getData().getHaveDoen());

                            if (badgeView4 == null) {
                                badgeView4 = new BadgeView(activity);
                                badgeView4.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeView4.setTextSize(8);
                                badgeView4.setTargetView(tv_no_wdjt);
                            }
                            badgeView4.setBadgeCount(jsonObject.getData().getMyProblemNum());
                            if (badgeView6 == null) {
                                badgeView6 = new BadgeView(activity);
                                badgeView6.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeView6.setTextSize(8);
                                badgeView6.setTargetView(tv_no_dfh);
                            }
                            badgeView6.setBadgeCount(jsonObject.getData().getDFH());
                            if (badgeView7 == null) {
                                badgeView7 = new BadgeView(activity);
                                badgeView7.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeView7.setTextSize(8);
                                badgeView7.setTargetView(tv_no_gzz);

                            }
                            badgeView7.setBadgeCount(jsonObject.getData().getGZZ());
                        }

                    }

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onstart() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }

    @Override
    protected void init() {
        super.init();
        EventBus.getDefault().register(this);
        getBanner();
        specialColumnBtnsRecyclrViewInit();
        viewPagerInit();
        patrolNewsInit();
//        getWeather();

        subscribe = Observable.interval(0, 360, TimeUnit.SECONDS, Schedulers.io()).subscribe(new Subscriber<Long>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(Long aLong) {
                getProblemList(SPUtil.get("userId", "null").toString());

            }
        });


    }

    /**
     * 获取天气
     */
    private void getWeather() {
        mquery = new WeatherSearchQuery("广州", WeatherSearchQuery.WEATHER_TYPE_LIVE);
        mweathersearch = new WeatherSearch(activity);
        mweathersearch.setOnWeatherSearchListener(new WeatherSearch.OnWeatherSearchListener() {
            @Override
            public void onWeatherLiveSearched(LocalWeatherLiveResult localWeatherLiveResult, int i) {
                weather.setText(localWeatherLiveResult.getLiveResult().getTemperature() + "℃ | " + localWeatherLiveResult.getLiveResult().getWeather());
            }

            @Override
            public void onWeatherForecastSearched(LocalWeatherForecastResult localWeatherForecastResult, int i) {

            }
        });
        mweathersearch.setQuery(mquery);
        mweathersearch.searchWeatherAsyn();
    }

    private void patrolNewsInit() {
        patrolNewsList = new LinkedList<IndexProblemListBean.DataBean>();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        patrolNewsRecyclerView.setLayoutManager(linearLayoutManager);

        patrolNewsAdapter = new TestAdapter(activity, patrolNewsList);
//        patrolNewsAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_LEFT);
//        patrolNewsAdapter.isFirstOnly(false);
        patrolNewsRecyclerView.setAdapter(patrolNewsAdapter);
    }

    /**
     * viewpager我的动态初始化
     */
    private void viewPagerInit() {
        fragment = new ArrayList<>();

        MyReportFragment myReportFragment = new MyReportFragment();
        fragment.add(myReportFragment);
        RecentNewsFragment recentNewsFragment = new RecentNewsFragment();
        fragment.add(recentNewsFragment);
        RepeatedComplaintsFragment repeatedComplaintsFragment = new RepeatedComplaintsFragment();
        fragment.add(repeatedComplaintsFragment);
        FragmentViewPagerAdapter fragmentViewPagerAdapter = new FragmentViewPagerAdapter(getActivity().getSupportFragmentManager(), fragment, new String[]{"我的提交", "最新动态", "重复投诉"});
        customViewPager.setAdapter(fragmentViewPagerAdapter);
        customViewPager.setOffscreenPageLimit(3);

        tb_title.setupWithViewPager(customViewPager);
    }


    /**
     * 专栏初始化
     */
    private void specialColumnBtnsRecyclrViewInit() {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(activity, 5) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        specialColumnBtnsRecyclrView.setLayoutManager(gridLayoutManager);
        specialColumnBtnsRecyclrView.addItemDecoration(new GridSpacingItemDecoration(5, 20, false));
        specialColumnBtnsRecyclrView.setItemAnimator(new DefaultItemAnimator());
        LinkedList<DailyBtnsBean> btnsList = new LinkedList<>();

        btnsList.add(new DailyBtnsBean(R.mipmap.xwdt, "新闻动态", NewsStaticActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.notice, "通知公告", NoticeActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.jyjl, "清河行动", ExperienceExchangeActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.tszs, "他山之石", OutsideBoxActivity.class));
//        //btnsList.add(new DailyBtnsBean(R.mipmap.tszs, "秀美河湖", OutsideBoxActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.zdgz, "河长须知", KeyAttentionActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.zcfg, "政策法规", PoliciesRegulationsActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.bhmc, "白海面涌", WhiteSeaRiverActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.bd, "红黑榜", ListActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.jfb, "积分榜", RankActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.notice, "通知公告", NewsStaticActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.ic_yzys, "一长一事", BuildingActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.yzyx, "一长一效", RankNaviActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.jyjl, "清河行动", NewsStaticActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.tszs, "他山之石", NewsStaticActivity.class));
//        //btnsList.add(new DailyBtnsBean(R.mipmap.tszs, "秀美河湖", OutsideBoxActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.zdgz, "河长须知", NewsStaticActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.zcfg, "政策法规", NewsStaticActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.bhmc, "白海面涌", TestScorllActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.bd, "红黑榜", ListActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.jfb, "积分榜", RankNaviActivity.class));
        DailyBtnsAdapter dailyBtnsAdapter = new DailyBtnsAdapter(btnsList, this);
        specialColumnBtnsRecyclrView.setAdapter(dailyBtnsAdapter);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refEventBus(ClickEvent message) {
        if (message.getMsg().equals("loging_success")) {
        }
    }

    /**
     * 快捷方式初始化
     */
    private void kjfsBtnsInit() {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(activity, 5) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        indexBtnsRecyclerview.setLayoutManager(gridLayoutManager);
        indexBtnsRecyclerview.addItemDecoration(new GridSpacingItemDecoration(5, 20, false));
        indexBtnsRecyclerview.setItemAnimator(new DefaultItemAnimator());
        LinkedList<DailyBtnsBean> btnsList = new LinkedList<>();
//        btnsList.add(new DailyBtnsBean(R.mipmap.rdjd, "人大监督", DeputiesMonitorActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.zxjd, "政协监督", CPPCCMonitorActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.ic_people_heart, "民间河长", PeopleHeartActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.assigned_thing, "市级督办", AssignedThingListActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.szxx, "水质信息", ShuiZhiActivity.class));
        if (!SPUtil.get("userType", "null").equals("21")) {//巡查专员屏蔽河湖名录与河长名录
            btnsList.add(new DailyBtnsBean(R.mipmap.hdxx, "河湖名录", RiverMsgActivity.class));
            btnsList.add(new DailyBtnsBean(R.mipmap.hzml, "河长名录", RiverChiefsNameListActivity.class));
        }
//        btnsList.add(new DailyBtnsBean(R.mipmap.hzxc, "河长巡河", null));
//        btnsList.add(new DailyBtnsBean(R.mipmap.wtsb, "问题上报", OtherProblemReportActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.wtcx, "事务公开", ProblemInfoActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.ic_ylh, "异龙湖", LakeMsgActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.ic_hhly, "红河流域", RedRiverMsgActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.ic_zjly, "珠江流域", ZjRiverMsgActivity.class));
//        btnsList.add(new DailyBtnsBean(R.mipmap.wdqd, "我的签到", MineActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.ic_xhdb, "巡河达标", RiverStaticActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.ic_wtbjl, "问题办结", ProblemStaticActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.ic_wxyy, "网箱养鱼", WxyyActivity.class));
        btnsList.add(new DailyBtnsBean(R.mipmap.ic_hdcs, "河道采砂", WxyyActivity.class));


        dailyBtnsAdapter = new DailyBtnsAdapter(btnsList, this);
        indexBtnsRecyclerview.setAdapter(dailyBtnsAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (subscription != null && subscription.isUnsubscribed()) {
            subscription.unsubscribe();

        }
    }


    @OnClick({R.id.tv_no_1, R.id.tv_no_2, R.id.tv_no_4, R.id.tv_no_5, R.id.tv_no_6, R.id.tv_no_7})
    public void onClick(View view) {
        if (view.getId() == R.id.tv_no_1) {
            Intent intent = new Intent(activity, ProblemWaitForAcceptActivity.class);
            intent.putExtra("type", 1);
            intent.putExtra("title", "待受理");
            intent.putExtra("addvcd", SPUtil.get("addvcd", "null").toString());
            startActivityForResult(intent, 200);
        } else if (view.getId() == R.id.tv_no_2) {
            Intent intent = new Intent(activity, ProblemWaitForAcceptActivity.class);
            intent.putExtra("type", 2);
            intent.putExtra("title", "处理中");
            intent.putExtra("addvcd", SPUtil.get("addvcd", "null").toString());
            startActivityForResult(intent, 200);
        } else if (view.getId() == R.id.tv_no_4) {
            Intent intent = new Intent(activity, ProblemWaitForAcceptActivity.class);
            intent.putExtra("type", 3);
            intent.putExtra("title", "已办结");
            intent.putExtra("addvcd", SPUtil.get("addvcd", "null").toString());
            startActivityForResult(intent, 200);
        } else if (view.getId() == R.id.tv_no_5) {
            Intent intent = new Intent(activity, ProblemAllActivity.class);
            startActivityForResult(intent, 200);
        } else if (view.getId() == R.id.tv_no_6) {
            Intent intent = new Intent(activity, WaitForToCheckActivity.class);
            startActivityForResult(intent, 200);
        } else if (view.getId() == R.id.tv_no_7) {
            Intent intent = new Intent(activity, ProblemBillActivity.class);
            startActivityForResult(intent, 200);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 200) {
            String userId = SPUtil.get("userId", "null").toString();
            getProblemNum(userId);
            getNewsUnreadNum(userId);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    /**
     * 获得首页新闻类栏目未读数量（红色圆点）
     *
     * @param userId
     */
    public void getNewsUnreadNum(String userId) {
        HttpManager.getInstance()
                .getNewsUnreadNums(userId)
                .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ApiSubscriber(activity, new ApiSubscriber.HttpOnResultListener<NewsUnreadNumsBean>() {
                    @Override
                    public void onNext(NewsUnreadNumsBean jsonObject) {
                        if (jsonObject.getData() != null) {
                            //新闻动态
                            if (badgeViewForNews == null) {
                                badgeViewForNews = new BadgeView(activity);
                                badgeViewForNews.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeViewForNews.setTextSize(9);

                                View view = specialColumnBtnsRecyclrView.getLayoutManager().findViewByPosition(0);
                                if (view == null)
                                    return;
                                LinearLayout layout = (LinearLayout) view;
                                ImageView imageView = (ImageView) layout.findViewById(R.id.image);
                                badgeViewForNews.setTargetView(imageView);
                            }
                            if (jsonObject.getData().getXwdtnums() > 0)
                                badgeViewForNews.setText("新");
                            else
                                badgeViewForNews.setText(null);

                            //通知公告
                            if (badgeViewForNotice == null) {
                                badgeViewForNotice = new BadgeView(activity);
                                badgeViewForNotice.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
                                badgeViewForNotice.setTextSize(9);

                                View view = specialColumnBtnsRecyclrView.getLayoutManager().findViewByPosition(1);
                                LinearLayout layout = (LinearLayout) view;
                                ImageView imageView = (ImageView) layout.findViewById(R.id.image);
                                badgeViewForNotice.setTargetView(imageView);
                            }
                            if (jsonObject.getData().getTzggnums() > 0)
                                badgeViewForNotice.setText("新");
                            else
                                badgeViewForNotice.setText(null);

//                            //经验交流
//                            if (badgeViewForExprence == null) {
//                                badgeViewForExprence = new BadgeView(activity);
//                                badgeViewForExprence.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
//                                badgeViewForExprence.setTextSize(9);
//
//                                View view = specialColumnBtnsRecyclrView.getLayoutManager().findViewByPosition(2);
//                                LinearLayout layout = (LinearLayout) view;
//                                ImageView imageView = (ImageView) layout.findViewById(R.id.image);
//                                badgeViewForExprence.setTargetView(imageView);
//                            }
//                            if (jsonObject.getData().getJyjlnums() > 0)
//                                badgeViewForExprence.setText("新");
//                            else
//                                badgeViewForExprence.setText(null);
//
//                            //他山之石
//                            if (badgeViewForOtherStone == null) {
//                                badgeViewForOtherStone = new BadgeView(activity);
//                                badgeViewForOtherStone.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
//                                badgeViewForOtherStone.setTextSize(9);
//
//                                View view = specialColumnBtnsRecyclrView.getLayoutManager().findViewByPosition(3);
//                                LinearLayout layout = (LinearLayout) view;
//                                ImageView imageView = (ImageView) layout.findViewById(R.id.image);
//                                badgeViewForOtherStone.setTargetView(imageView);
//                            }
//                            if (jsonObject.getData().getTszsnums() > 0)
//                                badgeViewForOtherStone.setText("新");
//                            else
//                                badgeViewForOtherStone.setText(null);
//
//                            //河长须知
//                            if (badgeViewForRiverchiefKnow == null) {
//                                badgeViewForRiverchiefKnow = new BadgeView(activity);
//                                badgeViewForRiverchiefKnow.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
//                                badgeViewForRiverchiefKnow.setTextSize(9);
//
//                                View view = specialColumnBtnsRecyclrView.getLayoutManager().findViewByPosition(4);
//                                LinearLayout layout = (LinearLayout) view;
//                                ImageView imageView = (ImageView) layout.findViewById(R.id.image);
//                                badgeViewForRiverchiefKnow.setTargetView(imageView);
//                            }
//                            if (jsonObject.getData().getHzxznums() > 0)
//                                badgeViewForRiverchiefKnow.setText("新");
//                            else
//                                badgeViewForRiverchiefKnow.setText(null);
//
//                            //政策法规
//                            if (badgeViewForPolicies == null) {
//                                badgeViewForPolicies = new BadgeView(activity);
//                                badgeViewForPolicies.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
//                                badgeViewForPolicies.setTextSize(9);
//
//                                View view = specialColumnBtnsRecyclrView.getLayoutManager().findViewByPosition(5);
//                                LinearLayout layout = (LinearLayout) view;
//                                ImageView imageView = (ImageView) layout.findViewById(R.id.image);
//                                badgeViewForPolicies.setTargetView(imageView);
//                            }
//                            if (jsonObject.getData().getZcfgnums() > 0)
//                                badgeViewForPolicies.setText("新");
//                            else
//                                badgeViewForPolicies.setText(null);
//
//                            //红黑榜
//                            if (badgeViewForRedBlackList == null) {
//                                badgeViewForRedBlackList = new BadgeView(activity);
//                                badgeViewForRedBlackList.setBadgeGravity(Gravity.TOP | Gravity.RIGHT);
//                                badgeViewForRedBlackList.setTextSize(9);
//
//                                View view = specialColumnBtnsRecyclrView.getLayoutManager().findViewByPosition(7);
//                                LinearLayout layout = (LinearLayout) view;
//                                ImageView imageView = (ImageView) layout.findViewById(R.id.image);
//                                badgeViewForRedBlackList.setTargetView(imageView);
//                            }
//                            if (jsonObject.getData().getHbhbnums() > 0)
//                                badgeViewForRedBlackList.setText("新");
//                            else
//                                badgeViewForRedBlackList.setText(null);
                        }

                    }

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onstart() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                }));
    }

    /**
     *
     */
}
